package com.kevin.common;

/**
 * 缓存前缀常量类
 *
 * @author wh
 * @date 2021-05-31
 */
public class CacheConstant {

    /**
     * 不设置过期时长
     */
    public final static long NOT_EXPIRE = -1L;

    /**
     * 默认过期时长为24小时，单位：秒
     */
    public final static long DEFAULT_EXPIRE = 60 * 60 * 24L;

    // 缓存名称
    public static final String CACHE_FAR = "CACHE_FAR";
    public static final String CACHE_LONG = "CACHE_LONG";
    public static final String CACHE_NORMAL = "CACHE";
    public static final String CACHE_SHORT = "CACHE_SHORT"; // 仅缓存20秒


    /** Token缓存前缀 */
    public static final String TOKEN = "AK_";

    /** 用户信息缓存前缀 */
    public static final String USER = "USER_";

    /** 防重提交限制 */
    public static final String REQUEST_LIMIT = "REQUEST_LIMIT";

    /**
     * 字典管理 cache key
     */
    public static final String SYS_DICT_KEY = "sys_dict:";

    /**
     * 分布式锁key
     */
    public static final String LOCK_KEY = "lock:";

    /**
     * 七陌Webcall id
     */
    public static final String QM_WEB_CALL_KEY = "QM_WEB_CALL:";

    /**
     * 验证码key
     */
    public static final String SYS_CODE_KEY = "code_";

    /**
     * 限制key
     */
    public static final String CODE_LIMIT_KEY = "CODE_LIMIT:";

    /**
     * AREA缓存
     */
    public static final String AREA_MAP_KEY = "AREA_MAP:";

    /**
     * 城市ID、城市名称、省份名称缓存
     */
    public static final String CITYID_CITYNAME_PROVINCENAME = "CITYID_CITYNAME_PROVINCENAME:";


    /**
     * 字典缓存
     */
    public static final String DICT_LABEL_KEY = "DICT_LABEL:";

    /**
     * 众投token key
     */
    public static final String THIRD_TOKEN_KEY_ZHONGTOU = "THIRD_TOKEN_ZHONGTOU";

    /**
     * 上饶token key
     */
    public static final String THIRD_TOKEN_KEY_SHANGRAO = "THIRD_TOKEN_SHANGRAO";

    /**
     * 异常key
     */
    public static final String EXCEPTION_KEY = "EXCEPTION:";

    /**
     * 抢单key
     */
    public static final String GRAB_ORDER = "GRAB_ORDER";

    /**
     * 订单log
     */
    public static final String ORDER_LOG_KEY = "ORDER_LOG:";

    /**
     * 小程序schema
     */
    public static final String MINI_SCHEMA = "MINI_SCHEMA:";

    /**
     * 抢单限制key
     */
    public static final String GRAB_LIMIT_KEY = "GRAB_LIMIT:";

    /**
     * 抢单分享key
     */
    public static final String GRAB_SHARE_KEY = "GRAB_SHARE:%s_%s";

    /**
     * axbKey
     */
    public static final String AXB_KEY = "AXB:%s_%s";

    /**
     * axbKey
     */
    public static final String ANSWER_LOCK = "AXB:";

    /**
     * axbKey
     */
    public static final String AXB_EXTEND = "AXB_EXTEND:";

    /**
     * expireSend
     */
    public static final String EXPIRE_SEND = "EXPIRE_SEND:";

    /**
     * expireSend
     */
    public static final String PRODUCT_CATEGORY = "PRODUCT_CATEGORY";


    /***********************************以下为时长常量*******************************************************/
    /** Token时长 */
    public static final Long TOKEN_SECOND = 60 * 60 * 2L;

    /** 用户信息时长 */
    public static final Long USER_SECOND = 60 * 60 * 2L;

    public static String getQmWebCallKey(String actionId) {
        return QM_WEB_CALL_KEY + actionId;
    }


    /** 获取验证码key */
    public static String getVerifyCodeKey(String mobile) {
        return SYS_CODE_KEY + mobile;
    }

    /** 获取验证码key */
    public static String getCodeLimitKey(String mobile) {
        return CODE_LIMIT_KEY + mobile;
    }

    /** 获取抢单key */
    public static String getGrabOrderKey(String orderId) {
        return CODE_LIMIT_KEY + orderId;
    }

    /** 获取抢单key */
    public static String getAreaMapKey(int deep) {
        return AREA_MAP_KEY + deep;
    }

    /** 获取字典LabelKey */
    public static String getDictLabelKey(String type) {
        return DICT_LABEL_KEY + type;
    }

    /** 获取异常key */
    public static String getExceptionKey(String exceptionHash) {
        return EXCEPTION_KEY + exceptionHash;
    }

    /** 获取异常key */
    public static String getOrderLogKey(String logId) {
        return ORDER_LOG_KEY + logId;
    }

    /** 获取异常key */
    public static String getMiniSchema(String appid) {
        return MINI_SCHEMA + appid;
    }

    /** 获取异常key */
    public static String getGrabLimitKey(Long merchantId) {
        return GRAB_LIMIT_KEY + merchantId;
    }

    /** 获取异常key */
    public static String getGrabShareKey(String date, Long merchantId) {
        return String.format(GRAB_SHARE_KEY, date, merchantId);
    }

    /** 获取异常key */
    public static String getAxbKey(String mobileA, String mobileB) {
        return String.format(AXB_KEY, mobileA, mobileB);
    }

    /** 获取异常key */
    public static String getAxbLockKey(Long scoreId, Long questionId) {
        return ANSWER_LOCK + scoreId + "_" + questionId;
    }

    /** 获取异常key */
    public static String getAxbExtendKey(String mobileX) {
        return AXB_EXTEND + mobileX;
    }

    /** 获取异常key */
    public static String getExpireSendKey(String key) {
        return EXPIRE_SEND + key;
    }

    /** 获取字典LabelKey */
    public static String getProductCategoryKey() {
        return PRODUCT_CATEGORY;
    }
}
